"use strict";
cc._RF.push(module, '17839u/7DhKxoL9gSuX3JkX', 'player_info_node');
// scripts/player_info_node.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AudioManager"),
    s = e("CommonHelper"),
    l = e("Game"),
    _ = e("ObjectPool"),
    c = e("role_effects_info"),
    d = e("role_node"),
    h = cc._decorator,
    u = h.ccclass,
    p = h.property,
    m = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.role_name_label = null, t.my_node = null, t.other_node = null, t.enemy_node = null, t.level_label = null, t.exp_node = null, t.flag_node = null, t.role_hp_node = null, t.level_num = 1, t.exp_num = 0, t.role_node_item = null, t.have_hp = 0, t.now_have_hp = 0, t.role_info = null, t.is_die = !1, t.player_index = 0, t.hero_kill_id = [-1, -1], t;
  }

  return nn(t, e), t.prototype.InfoInit = function (e, t) {
    this.player_index = e, this.role_node_item = t, this.unscheduleAllCallbacks(), this.schedule(this.showInfoPosition), this.hero_kill_id = [-1, -1];
    var o = i.GlobalParams.MatchGamePlayer[e];
    this.role_name_label.string = o.name, this.role_name_label.node.color = e == i.GlobalParams.MatchMyIndex ? cc.color(20, 255, 50) : cc.color(255, 255, 255), this.my_node.active = this.other_node.active = this.enemy_node.active = !1, e == i.GlobalParams.MatchMyIndex ? (this.role_hp_node = this.my_node, this.addRoleEffects(l.RoleEffectType.my_birth_light)) : e % 2 == i.GlobalParams.MatchMyIndex % 2 ? (this.role_hp_node = this.other_node, this.addRoleEffects(l.RoleEffectType.other_birth_light)) : this.role_hp_node = this.enemy_node, this.role_hp_node.active = !0, this.role_hp_node.width = 115, this.level_num = o.level, this.exp_num = o.exp_num, this.role_info = this.role_node_item.getComponent(d["default"]).role_info, this.getPlayerHp(), this.showPlayerLevel(), this.role_name_label.node.active = 2 != i.GlobalParams.MultiModeIndex, this.exp_node.active = 2 != i.GlobalParams.MultiModeIndex, this.level_label.node.active = 2 != i.GlobalParams.MultiModeIndex, this.my_node.setPosition(2 != i.GlobalParams.MultiModeIndex ? cc.v2(-58, 3) : cc.v2(-10, -15)), this.showOperateRoleInfo();
  }, t.prototype.showOperateRoleInfo = function () {
    2 == i.GlobalParams.MultiModeIndex && (this.flag_node.active = i.GlobalParams.MatchMyIndex == this.player_index, this.my_node.active = i.GlobalParams.MatchMyIndex == this.player_index, this.other_node.active = this.player_index < 3 && i.GlobalParams.MatchMyIndex != this.player_index, this.enemy_node.active = this.player_index > 2, this.my_node.width = this.other_node.width = 115 * this.now_have_hp / this.have_hp, i.GlobalParams.MatchMyIndex == this.player_index ? this.role_hp_node = this.my_node : this.player_index < 3 && (this.role_hp_node = this.other_node));
  }, t.prototype.showInfoPosition = function () {
    if (this.role_node_item && this.role_node_item.isValid) {
      var e = this.role_node_item.getPosition();
      this.node.setPosition(cc.v2(e.x, e.y + 230)), this.node.opacity = this.role_node_item.opacity;
    }
  }, t.prototype.addEvent = function () {
    this.attachEvent(n["default"].SEND_UPDATE_MATCH_PLAYER_INFO, this.showMatchPlayerInfo, this), this.attachEvent(n["default"].SEND_PLAYER_LEVEL_UP_INFO, this.playerLevelUp, this), this.attachEvent(n["default"].SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO, this.updatePlayerHp, this), this.attachEvent(n["default"].SEND_PLAYER_CHOOSE_OPERATE_HERO_INDEX, this.showOperateRoleInfo, this);
  }, t.prototype.showMatchPlayerInfo = function () {
    var e = i.GlobalParams.MatchGamePlayer[this.player_index];
    this.level_num = e.level, this.exp_num = e.exp_num, this.showPlayerLevel();
  }, t.prototype.playerLevelUp = function (e, t) {
    t == this.player_index && (this.addRoleEffects(l.RoleEffectType.level_up), this.player_index == i.GlobalParams.MatchMyIndex && r["default"].getInstance().playFx("level_up"), this.showMatchPlayerInfo(), this.getPlayerHp(), this.role_hp_node.width = 115);
  }, t.prototype.showPlayerLevel = function () {
    this.exp_node.width = 115 * this.exp_num / l["default"].level_exp[this.level_num - 1], this.level_label.string = "" + this.level_num;
  }, t.prototype.getPlayerHp = function () {
    this.have_hp = i.GlobalParams.GamePlayerInfo[this.player_index].hp + i.GlobalParams.BuyEquipInfo[this.player_index].hp, this.now_have_hp = this.have_hp;
  }, t.prototype.updatePlayerHp = function (e, t) {
    if (t == this.player_index) {
      var o = i.GlobalParams.GamePlayerInfo[this.player_index].hp + i.GlobalParams.BuyEquipInfo[this.player_index].hp,
          a = o - this.have_hp;
      this.now_have_hp = this.now_have_hp + a < 10 ? 10 : this.now_have_hp + a, this.have_hp = o + i.GlobalParams.BuyEquipInfo[this.player_index].die_up_hp * i.GlobalParams.MatchGamePlayer[this.player_index].kill_info[1], this.role_hp_node.width = 115 * this.now_have_hp / this.have_hp;
    }
  }, t.prototype.playerSkillAddHp = function () {
    this.setRoleAddHp(0.2 * this.have_hp);
  }, t.prototype.getRoleHpPercent = function () {
    return this.now_have_hp / this.have_hp * 100;
  }, t.prototype.getHpNotFull = function () {
    return this.now_have_hp < this.have_hp;
  }, t.prototype.setRoleAddHp = function (e) {
    e += e * s["default"].getRandomInt(-20, 20) / 100, e = Number(e.toFixed()), this.now_have_hp += e, this.now_have_hp >= this.have_hp ? this.now_have_hp = this.have_hp : this.emitEvent(n["default"].SEND_SHOW_BE_HIT_INFO, {
      attack: e,
      my_team: 2,
      end_pos: cc.v2(this.node.getPosition().x, this.node.getPosition().y)
    }), this.role_hp_node.width = 115 * this.now_have_hp / this.have_hp;
  }, t.prototype.roleSkillAddHp = function (e) {
    var t = this.have_hp * e;
    this.setRoleAddHp(t);
  }, t.prototype.roleBeHit = function (e, t) {
    var o = this;
    this.is_die || (this.now_have_hp -= e, this.emitEvent(n["default"].SEND_SHOW_BE_HIT_INFO, {
      attack: e,
      my_team: this.player_index % 2 == 0 ? 0 : 1,
      end_pos: cc.v2(this.node.getPosition().x, this.node.getPosition().y)
    }), this.hero_kill_id[0] != t && t < 7 && (this.hero_kill_id[1] = this.hero_kill_id[0], this.hero_kill_id[0] = t, this.unschedule(this.clearHelpKillInfo), this.scheduleOnce(this.clearHelpKillInfo, 3)), this.now_have_hp = this.now_have_hp < 0 ? 0 : this.now_have_hp, this.role_hp_node.width = 115 * this.now_have_hp / this.have_hp, this.emitEvent(n["default"].SEND_D_HERO_BE_HIT_INFO, {
      index: this.player_index,
      hit_hp: e
    }), this.now_have_hp <= 0 && !this.is_die && (this.is_die = !0, this.role_node_item.getComponent(d["default"]).showRoleDeath(), this.addRoleEffects(l.RoleEffectType.coin), this.scheduleOnce(function () {
      var e = i.GlobalParams.MatchGamePlayer[o.player_index],
          t = {
        role_index: o.player_index,
        cound_down: 10 * (e.level + e.kill_info[1])
      };

      if (t.role_index != i.GlobalParams.MatchMyIndex && s["default"].getRandomInt(0, 100) < 50) {
        var a = s["default"].getRandomInt(2, 5);
        t.cound_down = t.cound_down < a ? t.cound_down : a;
      }

      i.GlobalParams.PlayingRoleDie.push(t), o.emitEvent(n["default"].SEND_ROLE_BE_KILL_INFO, {
        kill: o.hero_kill_id[0],
        be_kill: o.player_index,
        team: o.player_index % 2 == 0 ? l.TeamInfo.left_team : l.TeamInfo.right_team,
        help_kill: o.hero_kill_id[1]
      }), 2 == i.GlobalParams.MultiModeIndex && o.player_index > 2 && o.emitEvent(n["default"].SEND_MONSTER_DIE_NUMBER_INFO), o.node.destroy();
    }, 0.01)));
  }, t.prototype.clearHelpKillInfo = function () {
    this.hero_kill_id[1] = -1;
  }, t.prototype.playerBeLight = function (e) {
    var t = this,
        o = 0.1 * this.have_hp;
    this.addRoleEffects(l.RoleEffectType.fill), this.roleBeHit(o, e), this.schedule(function () {
      t.roleBeHit(o, e);
    }, 0.5, 2);
  }, t.prototype.playerKillSkill = function (e) {
    var t = this,
        o = 0.2 * this.have_hp;
    this.addRoleEffects(l.RoleEffectType.kill), this.scheduleOnce(function () {
      t.roleBeHit(o, e);
    }, 1);
  }, t.prototype.addRoleEffects = function (e) {
    var t = _["default"].getInstance().creatPlane(l.Pool_Type.role_effects);

    t.active = !0, t.getComponent(c["default"]).showEffectInfo(e), t.setParent(this.role_node_item);
  }, oo([p(cc.Label)], t.prototype, "role_name_label", void 0), oo([p(cc.Node)], t.prototype, "my_node", void 0), oo([p(cc.Node)], t.prototype, "other_node", void 0), oo([p(cc.Node)], t.prototype, "enemy_node", void 0), oo([p(cc.Label)], t.prototype, "level_label", void 0), oo([p(cc.Node)], t.prototype, "exp_node", void 0), oo([p(cc.Node)], t.prototype, "flag_node", void 0), oo([u], t);
}(a["default"]);

o["default"] = m;

cc._RF.pop();